package com.party.controller.api;


import com.party.common.base.ApiResult;
import com.party.common.entity.MyPage;
import com.party.entity.PbUser;
import com.party.entity.dto.*;
import com.party.entity.vo.SelectUserVo;
import com.party.service.PbBannerService;
import com.party.service.PbUserService;
import com.party.util.ResultCode;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * <p>
 * 客户信息表 前端控制器
 * </p>
 *
 * @author ccl
 * @since 2024-10-25
 */
@RestController
@RequestMapping("api/pb-user")
@Api(tags = "用户相关api接口", value = "用户相关api接口")
public class PbUserController {

    @Resource
    private PbUserService pbUserService;

    @PostMapping("login")
    @ApiOperation("登录系统")
    public ApiResult login(@RequestBody ReqLoginDto loginReqDao){
        return pbUserService.login(loginReqDao);
    }

    @PostMapping("logout")
    @ApiOperation("退出系统")
    public ApiResult logout(@RequestBody ReqLogoutDto reqLogoutDao, HttpServletRequest request){
        String loginId = reqLogoutDao.getLoginId();
        pbUserService.logout(loginId,request);
        return ApiResult.ok(ResultCode.SUCCESS);
    }

    @PostMapping("add")
    @ApiOperation("保存用户")
    public ApiResult add(@RequestBody PbUser pbUser){
        return pbUserService.add(pbUser);

    }

    @PostMapping("update")
    @ApiOperation("编辑用户")
    public ApiResult update(@RequestBody PbUser pbUser){
        return pbUserService.edit(pbUser);
    }

    @GetMapping("delete")
    @ApiOperation("删除用户")
    public ApiResult delete(Long id){
        return ApiResult.ok(pbUserService.delete(id));
    }

    @PostMapping("queryPage")
    @ApiOperation("分页查询用户")
    public ApiResult<MyPage<PbUser>> queryPage(@RequestBody QueryUserDto queryUserDto){
        MyPage<PbUser> ccpSystemUserMyPage = pbUserService.queryPage(queryUserDto);
        return ApiResult.ok(ccpSystemUserMyPage);
    }

    @GetMapping("detail")
    @ApiOperation(value = "用户详情",response = PbUser.class)
    public ApiResult detail(Long id){
        return ApiResult.ok(pbUserService.detail(id));
    }

    @GetMapping("resetPassword")
    @ApiOperation("用户重置密码")
    public ApiResult resetPassword(Long id){
        return ApiResult.ok(pbUserService.resetPassword(id));
    }

    @PostMapping("modifyPassword")
    @ApiOperation("用户修改密码(头像、账号)")
    public ApiResult modifyPassword(@RequestBody ModifyPasswordDto modifyPasswordDao){
        return ApiResult.ok(pbUserService.modifyPassword(modifyPasswordDao));
    }

    @PostMapping("userSelect")
    @ApiOperation(value = "查询用户下拉框",response = SelectUserVo.class)
    public ApiResult<List<SelectUserVo>> findUserList() {
        return ApiResult.ok(pbUserService.userSelect());
    }

    @PostMapping("distribute")
    @ApiOperation(value = "用户分配设备和资源 分配类型 0-设备 1-资源",response = Boolean.class)
    public ApiResult<Boolean> distribute(@RequestBody DistributeDto dto) {
        return ApiResult.ok(pbUserService.distribute(dto));
    }

}

